package com.example.demo.model.sys.sys.controler;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.Results.ResultClass;
import com.example.demo.model.sys.sys.entity.SysMenu;
import com.example.demo.model.sys.sys.service.SysMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author STAHYW
 * @since 2021-09-29
 */
@Api(tags = "菜单")
@RestController
@RequestMapping("/sys/sysMenu")
public class SysMenuResource {

    @Autowired
    private SysMenuService sysMenuService;


    @ApiOperation(value = "进入主页", notes = "进入主页")
    @GetMapping("/main")
    public ModelAndView main() {
        ModelAndView mv = new ModelAndView();
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.orderByAsc("menu_order");
        List<SysMenu> sysMenu = sysMenuService.list(queryWrapper);
        mv.addObject("sysMenu",sysMenu);
        mv.setViewName("/sys/main");
        return mv;
    }

    @ApiOperation(value = "后台首页", notes = "后台首页")
    @GetMapping("index")
    public ModelAndView Index(){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("/sys/index");
        return mv;

    }

    @ApiOperation(value = "菜单列表", notes = "菜单列表")
    @GetMapping("/menuList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "页码", dataType = "Integer", example = "1"),
            @ApiImplicitParam(name = "pageSize", value = "每页数量", dataType = "Integer", example = "10")
    })
    public ModelAndView getMenu(Integer pageNo,Integer pageSize){

        return sysMenuService.getMenuList(pageNo,pageSize);
    }

    @GetMapping("/menuEdit")
    public ModelAndView menuEdit(Integer id){

        return sysMenuService.menuEdit(id);

    }

    @PostMapping("/menuEditDo")
    public ResultClass menuEditDo(SysMenu sysMenu){

        return sysMenuService.menuEditDo(sysMenu);

    }




}

